package wiki.servlets;

import java.io.IOException;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
 * 
 * @author <p><strong>JwTeam</strong></p> 
 * Responsabile delle funzioni di modifica delle pagine, per gli utenti abilitati
 */
public class ModifyServlet extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private HashMap<String, String> map=new HashMap<String, String>();
	
	@Override
	public void init() throws ServletException {
		map.put("h3", "./tmod");
		map.put("p", "./tmod");
		map.put("img", "./img");
		map.put("audio", "./audio");
		map.put("video", "./ymod");
		map.put("down", "./down");
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		HttpSession ses=req.getSession(false);
		if(ses!=null){
			boolean isDoc = (Boolean) ses.getAttribute("rights");
			if(isDoc){
		String name=req.getParameter("name");
		String type=req.getParameter("type");
		String ID=req.getParameter("ID");
		if(map.containsKey(type)){
			resp.sendRedirect(map.get(type)+"?name="+name+"&type="+type+"&ID="+ID);
		}
			}else {
				resp.sendRedirect("./html/errorpages/nopermessi.html");
			}
		} else{
			resp.sendRedirect("./html/LOGIN/login.html");
		}
		
	}
	
}
